<?php

namespace oa\models;

use Yii;

class Role extends BaseModel
{

    const SCENARIO_ADD     = 'add';
    const SCENARIO_EDIT    = 'edit';
    const SCENARIO_REMOVE  = 'remove';
    const SCENARIO_DISABLE = 'disable';
    const SCENARIO_ENABLE  = 'enable';

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'role';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['status', 'updated_uid', 'updated_at', 'created_at'], 'integer'],
            [['name'], 'string', 'max' => 32],
            [['remark'], 'string', 'max' => 100],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '用户组名称',
            'menu_ids' => '菜单ID',
            'remark' => '备注',
            'status' => '状态',
            'updated_uid' => '最后修改用户ID',
            'updated_at' => '最后修改时间',
            'created_at' => '创建时间',
        ];
    }

    public function behaviors()
    {
        return [
            $this->autosaveTimestamp(),
            $this->autosaveUid(),
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_ADD] = ['name', 'menu_ids', 'remark', 'status', 'updated_uid'];
        $scenarios[self::SCENARIO_EDIT] = ['name', 'menu_ids', 'remark', 'status', 'updated_uid'];
        $scenarios[self::SCENARIO_REMOVE] = ['status'];
        $scenarios[self::SCENARIO_DISABLE] = ['status'];
        $scenarios[self::SCENARIO_ENABLE] = ['status'];
        return $scenarios;
    }
}
